const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const htmlWebpackPlugin = new HtmlWebpackPlugin({
    template: path.resolve(__dirname, './public/index.html'),
});

module.exports = {
    mode: 'development',
    entry: path.resolve(__dirname, './src/index.js'),
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'js/[name].[hash].bundle.js',
    },
    module: {
        rules: [
            {
                test: /\.(mjs|js|jsx)$/,
                exclude: /node_modules/,
                use: ['babel-loader'],
            }
        ],
    },

    plugins: [
        htmlWebpackPlugin,
    ],

    resolve: {
        extensions: ['.mjs', '.js', '.jsx'],
    },

    devServer: { // 这部分根据自己的需求设置
        host: '127.0.0.1',
        port: 8009,
        hot: true,
        // proxy: {
        //  'api': {
        //      target: 'http://xx.xx.xx.xx:xxxx',
        //      pathRewrite: {
        //          '^/api': '/api'
        //      },
        //      changeOrigin: true,
        //  }
        // }
    }
};